-
Notifications
You must be signed in to change notification settings - Fork 531
Add AWS CDK implementation for basic-runtime sample #507
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This commit introduces a comprehensive CDK alternative to the existing CloudFormation basic-runtime sample, providing a cleaner and more maintainable Infrastructure as Code approach for deploying Amazon Bedrock AgentCore resources. - **Complete CDK stack** (`basic_runtime_stack.py`) with proper construct separation - **Dedicated IAM role construct** (`infra-utils/agentcore_role.py`) for reusability - **Custom Lambda function** (`infra-utils/build_trigger_lambda.py`) for CodeBuild automation - **S3 asset-based source packaging** eliminating Docker dependency for users - **ARM64 CodeBuild integration** with automated container image building - **Comprehensive documentation** matching CloudFormation sample structure - Uses S3 assets instead of inline code for better maintainability - Separates infrastructure utilities into dedicated `infra-utils/` directory - Implements proper CDK patterns with construct separation - Provides cleaner deployment experience (~5-10 min vs ~10-15 min) - **Basic Strands agent** (`agent-code/basic_agent.py`) with simple Q&A functionality - **ARM64 Dockerfile** optimized for AgentCore runtime requirements - **Proper dependency management** with isolated requirements - Updated title to reflect both CloudFormation and CDK options - Added comprehensive CDK section with architecture highlights - Included CDK prerequisites with version requirements (CDK 2.218.0+) - Updated repository structure to show new CDK directory layout - Added installation commands for required CDK dependencies - Complete documentation following CloudFormation sample structure - Detailed prerequisites, deployment, testing, and cleanup instructions - Sample queries and troubleshooting sections - Architecture explanation and use case descriptions - **CDK 2.218.0+** required for BedrockAgentCore construct support - **Python 3.8+** and **constructs>=10.0.79** for proper CDK functionality - **S3 assets** for source code packaging without size limitations - ECR repository for container image storage - CodeBuild project with ARM64 support for automated builds - Lambda function for build orchestration and completion waiting - AgentCore Runtime with proper IAM permissions and networking - Custom resource for deployment automation - ✅ Successfully deployed and tested in AWS environment - ✅ Verified agent functionality with sample queries - ✅ Confirmed clean resource cleanup with `cdk destroy` - Added David Kaleko to CONTRIBUTORS.md This implementation provides a modern, maintainable alternative to CloudFormation while maintaining feature parity and following AWS CDK best practices.
…tilities This commit fixes critical Lambda function import errors that were preventing the CDK stack deployment from completing, and reorganizes the infrastructure utilities for better Python module compatibility. - **Root cause**: `cfnresponse` module is only available for inline CloudFormation Lambda code, not when using CDK's `Code.from_asset()` approach - **Solution**: Embedded the standard AWS-provided cfnresponse functionality directly into the Lambda function to eliminate import dependencies - **Impact**: Custom resource now properly signals CloudFormation completion/failure - **Renamed**: `infra-utils/` → `infra_utils/` for proper Python module imports - **Fixed**: Lambda handler path to use correct Python module notation - **Updated**: Import statements to use underscore-based directory name - Embedded cfnresponse class with SUCCESS/FAILED constants and send() method - Added comprehensive comments explaining why local cfnresponse is necessary - Maintains full compatibility with CloudFormation custom resource protocol - Proper error handling and CloudWatch logging integration - Updated Lambda handler path: `infra_utils.build_trigger_lambda.handler` - Fixed import statements for renamed directory structure - Removed conditional BedrockAgentCore imports (always available in CDK 2.218.0+) - Moved infrastructure utilities to properly named Python package - Added package `__init__.py` for proper module structure - Maintained clean separation between infrastructure and agent code - ✅ Resolves hanging CloudFormation deployments - ✅ Custom resource now properly waits for CodeBuild completion - ✅ Stack deployment completes successfully end-to-end - ✅ Maintains compatibility with existing CloudFormation approach - Verified Lambda function executes without import errors - Confirmed CodeBuild triggering and monitoring functionality - Validated complete stack deployment cycle This fix ensures the CDK implementation works reliably and follows Python packaging best practices while maintaining the same deployment behavior as the CloudFormation equivalent.
|
FYI I ran this code through an ASH security scan and (after some small changes to the Dockerfile which were included in my latest push) there are 0 vulnerabilities of any level found. |
Signed-off-by: David Kaleko <[email protected]>
|
@kaleko L2 constructs are coming soon. Here are the public PRs you can track:
|
evandrofranco
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please review all comments + these two:
- Can the folder name be
01-getting-started-with-strandsinstead ofbasic-runtime - Can the created agent name be
getting_started_with_cdkinstead ofBasicAgentDemo_BasicAgent.
|
Latest scan for commit: Security Scan ResultsScan Metadata
SummaryScanner ResultsThe table below shows findings by scanner, with status based on severity thresholds and dependencies: Column Explanations: Severity Levels (S/C/H/M/L/I):
Other Columns:
Scanner Results:
Severity Thresholds (Thresh Column):
Threshold Source: Values in parentheses indicate where the threshold is configured:
Statistics calculation:
|
|
@evandrofranco I'll implement these changes shortly. One clarification:
This is also why I called the agent "BasicAgent", that is what it is called in the symmetrical CFN example |
|
@evandrofranco I incorporated your changes except for the renaming of BasicAgent and the directory, per my previous comment. Let me know what you think |
evandrofranco
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved.
Amazon Bedrock AgentCore Samples Pull Request
Important
review readylabel to it. Only PRs withreview readywill be reviewed.Issue number:
Concise description of the PR
User experience
Before this change:
After this change:
cdk deployChecklist
If your change doesn't seem to apply, please leave them unchecked.
Acknowledgment
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of the project license.